package com.miyake.loveviewweb.client.main;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HasText;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.client.ui.MenuItem;
import com.miyake.loveviewweb.client.DataServiceWrapper;

public class DesktopMenu extends Composite implements HasText {

    private static DesktopMenuUiBinder uiBinder = GWT
        .create(DesktopMenuUiBinder.class);
    @UiField MenuItem menuCreateFolder;
    @UiField MenuItem menuCreateData;
    @UiField MenuItem menuDelete;
    @UiField MenuItem menuCreateRootFolder;
    @UiField MenuItem menuCreateChart;
    @UiField MenuItem menuCreateTable;
    @UiField MenuItem menuUpload;
    @UiField MenuItem menuPluginProvider;
    @UiField MenuItem menuPluginMarket;

    interface DesktopMenuUiBinder extends UiBinder<Widget, DesktopMenu> {
    }

    public DesktopMenu(UiDataHandler handler) {
        initWidget(uiBinder.createAndBindUi(this));
        initialize(handler);
    }

    private void initialize(final UiDataHandler handler) {
        menuCreateRootFolder.setCommand(new Command() {

            public void execute() {
                handler.createRootFolder();
            }
            
        });
        
        menuCreateFolder.setCommand(new Command() {

            public void execute() {
                handler.createFolder();
            }
            
        });
        menuCreateData.setCommand(new Command() {

            public void execute() {
                handler.createData();
            }
            
        });
        menuDelete.setCommand(new Command() {

            public void execute() {
                handler.delete();
            }
            
        });
        
        menuCreateChart.setCommand(new Command() {

            public void execute() {
                handler.createChart(DataServiceWrapper.getInstance().getSelectedData());
            }
            
        });
        
        menuUpload.setCommand(new Command() {

            public void execute() {
                handler.upload();
            }
            
        });
        
        menuPluginProvider.setCommand(new Command() {

            public void execute() {
                handler.pluginProvider();
            }
            
        });
        
        menuPluginMarket.setCommand(new Command() {

            public void execute() {
                handler.pluginMarket();
            }
            
        });
       
    }

    public DesktopMenu(String firstName, UiDataHandler handler) {
        initWidget(uiBinder.createAndBindUi(this));
        initialize(handler);
    }

    public void setText(String text) {
 
    }

    public String getText() {
        return "";
    }

}
